package es.index.logs.parse.squid;

import java.util.Date;

import es.index.document.logs.squid.SquidRefererLog;
import es.index.logs.parse.LogsBaseParse;

public class SquidRefererLogsParse extends LogsBaseParse {
	
	public SquidRefererLogsParse() {
		super();
		String keys = "set_date,set_ip,set_referer,set_uri";
		_keys = keys.split(",");
	}

	@Override
	protected Object getLogs() {
		SquidRefererLog log = new SquidRefererLog();
		log.set_id(ID());
		log.set_fileName(_fileName);
		setClassValue(log, 0, null, null);
		return log;
	}

	@Override
	protected void getNextIndex(String methodName, int currentIndex) {
		if (currentIndex == _keys.length - 1) {
			_index = _line.length();
		} else {
			if (methodName.equals("set_referer"))
				_index = _line.lastIndexOf(' ');
			else
				_index = _line.indexOf(' ');
		}
	}

	@Override
	protected void initParseParamete() {
		initParseParamete(SquidRefererLog.class);
	}

	@Override
	protected Date getDate() {
		return getNumDate();
	}

}
